<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Java web," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="说明：Web Server配置使用，包括Apache、Tomcat、Jetty等。">
<meta name="keywords" content="Java web">
<meta property="og:type" content="article">
<meta property="og:title" content="Web Server">
<meta property="og:url" content="http://bebetter.site/2017/01/12/Software/Java Web/Web Server/index.html">
<meta property="og:site_name" content="gatewayzy">
<meta property="og:description" content="说明：Web Server配置使用，包括Apache、Tomcat、Jetty等。">
<meta property="og:updated_time" content="2017-01-12T05:58:56.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Web Server">
<meta name="twitter:description" content="说明：Web Server配置使用，包括Apache、Tomcat、Jetty等。">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"right","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://bebetter.site/2017/01/12/Software/Java Web/Web Server/"/>

  <title> Web Server | gatewayzy </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-right page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">gatewayzy</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">blog of gatewayzy</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Web Server
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2017-01-12T13:58:23+08:00" content="2017-01-12">
              2017-01-12
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/Softwares/" itemprop="url" rel="index">
                    <span itemprop="name">Softwares</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><strong>说明：</strong>Web Server配置使用，包括Apache、Tomcat、Jetty等。<br><a id="more"></a></p>
<h2 id="Apache"><a href="#Apache" class="headerlink" title="Apache"></a>Apache</h2><hr>
<ul>
<li>简介<ul>
<li>对静态资源的服务效率非常高，但动态资源效率不高。</li>
</ul>
</li>
</ul>
<p>Ubuntu下安装使用如下。Windows下更加简单。</p>
<ul>
<li>安装<ul>
<li>安装apache：sudo apt-get install apache</li>
</ul>
</li>
<li>配置<ul>
<li>配置文件：/etc/apache2/apache2.conf</li>
<li>配置文件中引用了端口文件、目录文件等，可修改相应的端口、网站文件路径等。</li>
</ul>
</li>
<li>服务命令：service apache2 start|stop|restart|status|…</li>
</ul>
<h2 id="Jetty"><a href="#Jetty" class="headerlink" title="Jetty"></a>Jetty</h2><hr>
<h3 id="Jetty介绍"><a href="#Jetty介绍" class="headerlink" title="Jetty介绍"></a>Jetty介绍</h3><hr>
<ul>
<li>Jetty是eclipse基金会开发，和apache的tomcat二者是目前最为流行的开源的web server / servlet容器，都遵循java servlet规范。</li>
<li>相比之下，jetty比tomcat要轻量级，功能少，可通过插件和拓展，耗费资源比tomcat少。所以企业级应用一般用tomcat，小型应用用jetty方便些。</li>
</ul>
<h3 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h3><hr>
<ul>
<li>到jetty官网下载相应版本、位数即可。一般都是非安装文件的插件包形式，需要在IDE中设置相应的jetty路径。</li>
</ul>
<h3 id="主要端口号"><a href="#主要端口号" class="headerlink" title="主要端口号"></a>主要端口号</h3><hr>
<ul>
<li>http端口号默认是8080，一般在/etc/jetty-http.xml中设置。如<code>&lt;Set name=&quot;port&quot;&gt;&lt;Property name=&quot;jetty.http.port&quot; deprecated=&quot;jetty.port&quot; default=&quot;8080&quot; /&gt;&lt;/Set&gt;</code>。 如果没有的话，尝试查找其他相似的xml文件。</li>
<li>Maven运行时修改端口号示例：mvn jetty:run -Djetty.port=8081</li>
</ul>
<h2 id="Tomcat"><a href="#Tomcat" class="headerlink" title="Tomcat"></a>Tomcat</h2><hr>
<ul>
<li>参考文章：<ul>
<li><a href="http://www.toutiao.com/i6387497067698192897/" target="_blank" rel="external">Tomcat的详解和Tomcat的面试问题</a></li>
</ul>
</li>
</ul>
<h3 id="Tomcat安装启动"><a href="#Tomcat安装启动" class="headerlink" title="Tomcat安装启动"></a>Tomcat安装启动</h3><ul>
<li>启动与关闭猫<ul>
<li>启动可以运行startup.bat（win）或者startup.sh（linux），正常关闭时通过运行shutdown.bat/sh。</li>
</ul>
</li>
<li><p>设置tomcat自启动</p>
<ul>
<li>Windows本地服务下已存在tomcat服务的话，属性设置为自启动即可。</li>
<li>Windows下添加计划任务，设置开机后自启动startup.bat即可。</li>
</ul>
</li>
<li><p>将Tomcat安装为服务</p>
<ul>
<li>cmd进入bin，运行 <code>service.bat install</code>。如果失败尝试配置以下环境变量。</li>
</ul>
<ol>
<li>设置环境变量CATALINA_HOME：Tomcat路径</li>
<li>修改Path环境变量，在path中加入：%CATALINA_HOME%\bin;</li>
</ol>
</li>
</ul>
<h3 id="发布项目"><a href="#发布项目" class="headerlink" title="发布项目"></a>发布项目</h3><ul>
<li>将项目打包后，将war包等类型包复制到tomcat的webapps目录下。Tomcat配置无误后，启动tomcat会自动解压war包以及webapps下其他的所有项目。（如果无法正常启动，应查看tomcat下logs中的日志排查问题。）</li>
<li>如果是普通web工程，只需在tomcat的webapps中添加项目文件夹，将项目WEB-INF一级的文件拷贝到文件夹中，启动tomcat即可自动发布。</li>
</ul>
<h3 id="Tomcat-界面管理与设置"><a href="#Tomcat-界面管理与设置" class="headerlink" title="Tomcat 界面管理与设置"></a>Tomcat 界面管理与设置</h3><ul>
<li>设置tomcat的用户名密码，conf/tomcat-users.xml中设置user、role、passwd。</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">&lt;role rolename=&quot;tomcat&quot;/&gt;</div><div class="line">&lt;role rolename=&quot;role1&quot;/&gt;</div><div class="line">&lt;role rolename=&quot;manager&quot;/&gt; </div><div class="line">&lt;role rolename=&quot;manager-gui&quot;/&gt;</div><div class="line">&lt;role rolename=&quot;admin&quot;/&gt;  </div><div class="line">&lt;role rolename=&quot;admin-gui&quot;/&gt;  </div><div class="line">&lt;role rolename=&quot;manager-script&quot;/&gt;  </div><div class="line">&lt;role rolename=&quot;manager-jmx&quot;/&gt;  </div><div class="line">&lt;role rolename=&quot;manager-status&quot;/&gt; </div><div class="line">&lt;user username=&quot;tomcat&quot; password=&quot;tomcat&quot; roles=&quot;tomcat&quot;/&gt;</div><div class="line">&lt;user username=&quot;both&quot; password=&quot;tomcat&quot; roles=&quot;tomcat,role1&quot;/&gt;</div><div class="line">&lt;user username=&quot;role1&quot; password=&quot;tomcat&quot; roles=&quot;role1&quot;/&gt;</div><div class="line">&lt;user username=&quot;admin&quot; password=&quot;admin&quot; roles=&quot;tomcat,role1&quot;/&gt;</div><div class="line">&lt;user username=&quot;tomcat&quot; password=&quot;&quot; roles=&quot;manager-gui&quot;/&gt;</div><div class="line">&lt;user username=&quot;Tomcat&quot; password=&quot;Tomcat&quot; roles=&quot;admin-gui,admin,manager-gui,manager,manager-script,manager-jmx,manager-status&quot;/&gt;</div></pre></td></tr></table></figure>
<ul>
<li>前台进入manager app界面，使用“Tomcat”账户登录对工程进行管理：stop、start、reload等。前台还可以对tomcat的其他setting进行设置。</li>
</ul>
<h3 id="Tomcat主要端口"><a href="#Tomcat主要端口" class="headerlink" title="Tomcat主要端口"></a>Tomcat主要端口</h3><ul>
<li>Tomcat的端口设置在conf/sever.xml中。一般每一个猫要设置不同的shutdown端口、http端口、AJP端口。</li>
<li>SHUTDOWN 远程停服务端口，默认8005，用于命令行下通过端口关闭服务。<br><code>&lt;Server port=&quot;8005&quot; shutdown=&quot;SHUTDOWN&quot;&gt;</code></li>
<li>HTTP端口，默认8080<br><code>&lt;Connector port=&quot;8080&quot; protocol=&quot;HTTP/1.1&quot;  connectionTimeout=&quot;20000&quot;
redirectPort=&quot;8443&quot;  URIEncoding=&quot;UTF-8&quot;/&gt;</code><br>其中URIEncoding=”UTF-8”设置URI使用UTF-8编码。</li>
<li>AJP端口，默认8009<br><code>&lt;Connector port=&quot;8009&quot; protocol=&quot;AJP/1.3&quot; redirectPort=&quot;8443&quot; /&gt;</code></li>
</ul>
<h3 id="tomcat的体系结构"><a href="#tomcat的体系结构" class="headerlink" title="tomcat的体系结构"></a>tomcat的体系结构</h3><hr>
<ul>
<li>tomcat提供service、engine、host、web(context)应用分层。<ul>
<li>一个tomcat server一般运行一个Catalina service。</li>
<li>service监听各种用户请求的connector协议，并通过Catalina内置的engine进行请求指派，路由到各个虚拟host主机。</li>
<li>host包含多个web应用（对应context配置），进行请求处理。<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">&lt;Server port=&quot;8105&quot; shutdown=&quot;SHUTDOWN&quot;&gt;</div><div class="line">&lt;Service name=&quot;Catalina&quot;&gt;</div><div class="line">&lt;Connector port=&quot;8180&quot; protocol=&quot;HTTP/1.1&quot; connectionTimeout=&quot;20000&quot;&gt;</div><div class="line">&lt;Engine name=&quot;Catalina&quot; defaultHost=&quot;localhost&quot;&gt;</div><div class="line">&lt;Host name=&quot;localhost&quot;  appBase=&quot;webapps&quot; autoDeploy=&quot;true&quot;&gt;</div><div class="line">…</div><div class="line">&lt;/Host&gt;</div><div class="line">&lt;Host name=&quot;www.taobao.com&quot; appBase=&quot; d:\web1&quot; autoDeploy=&quot;true&quot;&gt;</div><div class="line">&lt;Context path=”/” docBase=”d:\web1”&gt; (只需本机拥有该域名或修改hosts文件)</div><div class="line">&lt;/Host&gt;</div><div class="line">&lt;/Engine&gt;</div><div class="line">&lt;/Service&gt;</div><div class="line">&lt;/Server&gt;</div></pre></td></tr></table></figure>
</li>
</ul>
</li>
</ul>
<h3 id="catalina-bat"><a href="#catalina-bat" class="headerlink" title="catalina.bat"></a>catalina.bat</h3><ul>
<li>编辑Catalina.bat，可以查看运行猫时使用的各种运行环境的配置，部分参数如下。<ul>
<li>CATALINA_HOME    catalina目录</li>
<li>CATALINA_OPTS        catalina运行参数</li>
<li>CATALINA_TMPDIR    catalina临时目录</li>
<li>JAVA_HOME        jdk目录，默认是系统环境变量JAVA_HOME指定，使用debug模式时必要</li>
<li>JRE_HOME            jre目录，优先使用JRE_HOME值，若空则使用上面的JAVA_HOME</li>
<li>JAVA_OPTS            jre运行参数</li>
<li>JAVA_ENDORSED_DIRS    </li>
<li>JPDA_TRANSPORT</li>
<li>JPDA_ADDRESS</li>
<li>JPDA_SUSPEND</li>
<li>JPDA_OPTS</li>
<li>LOGGING_CONFIG    登录设置</li>
<li>LOGGING_MANAGER    日志管理</li>
<li>TITLE                运行窗口名</li>
</ul>
</li>
<li>不同的tomcat可以按照需要配置不同jre配置、title等。</li>
<li><p>修改使用不同的jre<br>如要修改使用不同的jre，可以编辑tomcat/bin/setclasspath.bat在<code>rem Otherwise either JRE or JDK are fine</code>之前加上路径配置，如 <code>set JAVA_HOME = C:\....   jdk路径</code>、 <code>set JRE_HOME = C:\....\jre  Jre路径</code></p>
</li>
<li><p>修改tomcat运行窗口名<br>如要修改tomcat运行窗口名，只要编辑catalina.bat，找到<code>if &quot;%TITLE%&quot; == &quot;&quot; set TITLE=Tomcat</code> 修改标题为 <code>TITLE=MyApp:8070</code></p>
</li>
</ul>
<h3 id="Tomcat集群"><a href="#Tomcat集群" class="headerlink" title="Tomcat集群"></a>Tomcat集群</h3><hr>
<h4 id="安装与配置"><a href="#安装与配置" class="headerlink" title="安装与配置"></a>安装与配置</h4><ul>
<li>一般只需要设置shutdown、HTTP1.1、AJP端口不同就可以了，运行情况可以通过查看日志解决，包括程序输出日志Catalina.out，localhost-access.log等日志。</li>
<li>设置不同的3个端口，最好修改TITLE，进入相应目录进行批处理。</li>
</ul>
<h4 id="共享session"><a href="#共享session" class="headerlink" title="共享session"></a>共享session</h4><ul>
<li>目前使用tomcat做session共享有下面几种方式：<ul>
<li>使用 filter 方法存储<ul>
<li>这种方法比较推荐，因为它的服务器使用范围比较多，不局限于 tomcat ，而且实现的原理比较简单容易控制。 可以使用 <a href="http://code.google.com/p/memcached-session-filter/" target="_blank" rel="external">memcached-session-filter</a></li>
</ul>
</li>
<li>使用 tomcat session manager 方法存储<ul>
<li>这种方法服务器只能使用 tomcat ，网上有针对 memcached 和 redis 实现，直接配置就行了。</li>
<li>如Memcached就是安装Memcached，再设置tomcat配置context.xml中启用模块的方式。但是注意需要添加相应的jar文件到tomcat的lib中。</li>
<li>redis也是类似的。准备好redis服务器，在tomcat的lib中添加支持的jar包，然后配置tomcat的context.xml。</li>
</ul>
</li>
<li>使用 terracotta 等服务器共享session，经常结合spring-session框架实现。</li>
</ul>
</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">&lt;!-- Memcached  session --&gt;</div><div class="line">&lt;Manager</div><div class="line">className=&quot;de.javakaffee.web.msm.MemcachedBackupSessionManager&quot;  </div><div class="line">memcachedNodes=&quot;n1:10.15.62.55:11211 n1:10.15.62.58:11211&quot;  </div><div class="line">sticky=&quot;false&quot;  </div><div class="line">sessionBackupAsync=&quot;false&quot;  </div><div class="line">lockingMode=&quot;uriPattern:/path1|/path2&quot;  </div><div class="line">requestUriIgnorePattern=&quot;.*\.(ico|png|gif|jpg|css|js)$&quot;  </div><div class="line">transcoderFactoryClass=&quot;de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory&quot;/&gt;</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">&lt;!-- redis session --&gt;</div><div class="line">&lt;Context&gt;</div><div class="line">    &lt;Valve className=&quot;com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve&quot; /&gt;</div><div class="line">    &lt;Manager className=&quot;com.orangefunction.tomcat.redissessions.RedisSessionManager&quot;</div><div class="line">           host=&quot;10.15.82.57&quot;</div><div class="line">           port=&quot;6379&quot;</div><div class="line">           password=&quot;password&quot;</div><div class="line">           database=&quot;0&quot;</div><div class="line">           maxInactiveInterval=&quot;60&quot; /&gt;</div><div class="line">&lt;/Context&gt;</div></pre></td></tr></table></figure>
<h4 id="脚本管理tomcat集群"><a href="#脚本管理tomcat集群" class="headerlink" title="脚本管理tomcat集群"></a>脚本管理tomcat集群</h4><hr>
<ul>
<li>批处理流程一般是：更新项目代码，编译成文件，停止tomcat，拷贝项目到webapps下，启动tomcat。</li>
<li>Windows脚本<ul>
<li>注意Windows下使用call调用程序，如需等待call的程序执行完毕，可以用定时timeout 3 等待3秒。</li>
</ul>
</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">echo stopping tomcats...</div><div class="line">cd tomcat20123\bin\</div><div class="line">call .\shutdown.bat</div><div class="line">cd ..\..\tomcat20122\bin\</div><div class="line">call .\shutdown.bat</div><div class="line">cd ..\..\tomcat20121\bin\</div><div class="line">call .\shutdown.bat</div><div class="line">echo &quot;deploy tomcats for tcm...&quot;</div><div class="line">call .\startup.bat</div><div class="line">cd ..\..\tomcat20122\bin\</div><div class="line">call .\startup.bat</div><div class="line">cd ..\..\tomcat20123\bin\</div><div class="line">call .\startup.bat</div><div class="line">echo &quot;tomcats have been startup.&quot;</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line">echo  updating svn...</div><div class="line">cd \Program Files\svn\tcm</div><div class="line">svn update</div><div class="line">echo mvn package..</div><div class="line">call mvn clean package -Pplatform -Dmaven.test.skip=true</div><div class="line">echo stopping tomcats...</div><div class="line">cd ..\..\tomcats\tcm\bin </div><div class="line">call .\shutdown.bat</div><div class="line">:waiting for shutdown</div><div class="line">timeout 5</div><div class="line">echo deleting old war...</div><div class="line">del –f –s -q ..\webapps\tcm*</div><div class="line">rd /s /q ..\webapps\tcm</div><div class="line">echo copy new war...</div><div class="line">copy ..\..\..\svn\tcm\target\tcm.war ..\webapps\</div><div class="line">echo starting tomcat...</div><div class="line">call .\startup.bat</div><div class="line">echo tomcat restarted!</div></pre></td></tr></table></figure>
<ul>
<li>Ubuntu脚本<ul>
<li>Ubuntu下使用chmod +777 a.sh允许运行权限。</li>
<li>如果出现<code>#!/bin/bash - no such file or directory</code>错误，查看文件头$ head -1 a.sh | od –c。错误头是：<code>0000000   #   !   /   b   i   n   /   b   a   s   h  \r  \n</code>。正确的是<code>0000000   #   !   /   b   i   n   /   b   a   s   h  \n</code>。处理方法可以是：直接touch一个文件，代码复制进去。</li>
<li>启用防火墙的端口：sudo ufw allow|deny 8080|tcp|端口或协议</li>
<li>关闭集群流程：查找端口占用的进程，关闭各个进程。</li>
</ul>
</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line">#!/bin/bash</div><div class="line">PROJECT=&quot;usercenter&quot;</div><div class="line">cd ./svn/usercenter/</div><div class="line">echo &quot;going to update project: $&#123;PROJECT&#125;.&quot;</div><div class="line">svn update</div><div class="line">mvn clean package -Dmaven.test.skip=true</div><div class="line">echo &quot;mvn package done.&quot;</div><div class="line">./../../sh/shutdown.sh</div><div class="line">echo &quot;tomcats have been shutdown.&quot;</div><div class="line">rm  ../../1/webapps/$&#123;PROJECT&#125;* -r</div><div class="line">rm  ../../2/webapps/$&#123;PROJECT&#125;* -r</div><div class="line">rm  ../../3/webapps/$&#123;PROJECT&#125;* -r</div><div class="line">echo &quot;going to copy $&#123;PROJECT&#125;.war to all webapps.&quot;</div><div class="line">cp ./target/$&#123;PROJECT&#125;.war   ../../1/webapps/</div><div class="line">cp ./target/$&#123;PROJECT&#125;.war   ../../2/webapps/</div><div class="line">cp ./target/$&#123;PROJECT&#125;.war   ../../3/webapps/</div><div class="line">./../../sh/startup.sh</div><div class="line">echo &quot;tomcats have been startup.&quot;</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">echo &quot;kill all tomcats&quot;</div><div class="line">ID=`lsof -i:8103 |tail -1 | awk &apos;&#123;print $2&#125;&apos;`</div><div class="line">echo $ID</div><div class="line">for id in $ID</div><div class="line">do</div><div class="line">  kill -9 $id</div><div class="line">  echo &quot;killed $id&quot;</div><div class="line">done</div><div class="line">echo &quot;#############################&quot;</div></pre></td></tr></table></figure>
<h3 id="tomcat-启用-https"><a href="#tomcat-启用-https" class="headerlink" title="tomcat 启用 https"></a>tomcat 启用 https</h3><p>参考文章 <a href="http://www.cnblogs.com/sixiweb/p/3339698.html" target="_blank" rel="external">tomcat7+jdk的keytool生成证书 配置https</a></p>
<ul>
<li><p>window下https</p>
<ol>
<li>确定tomcat使用的jdk。以使用系统环境变量中的jdk1.8为例。</li>
<li>用jdk生成keystore文件并导出证书<ol>
<li>%JAVA_HOME%\bin\keytool -genkey -alias sr -keyalg RSA  # 这是设置证书别名叫sr，别名任选不重复就行</li>
<li>输入信息，假设密码是changeit，填写要求的信息，国家代码用cn，正确按y，输入tomcat的秘钥口令也假设为changeit。</li>
<li>会在用户主目录生成.keystore文件，将其拷贝到tomcat的bin目录下。</li>
<li>在tomcat的bin目录下运行命令：keytool -selfcert -alias sr -keystore .keystore，输入之前的命令changeit</li>
<li>接着运行keytool -export -alias sr -keystore .keystore -storepass changeit -rfc -file sr.cer 会导出证书sr.cer</li>
</ol>
</li>
<li>tomcat启用https<ul>
<li>配置tomcat/conf/server.xml</li>
<li>找到<code>&lt;Connector port=&quot;8443&quot;</code> 取消注释并改成<code>port=&quot;443&quot; ... sslProtocol=&quot;TLS&quot; keystoreFile=&quot;bin/.keystore&quot; keystorePass=&quot;changeit&quot; /&gt;</code></li>
<li>上面设置了https采用默认端口443，且配置http是证书。重启tomcat，访问https/127.0.0.1/ </li>
<li>正常的话，应该会提示https不安全，证书不安全，点击继续访问后可以访问页面。</li>
</ul>
</li>
<li>用户安装证书<ul>
<li>将证书sr.cer发给使用者，让他们安装该证书（具体步骤同12306.cn网站证书的安装步骤）</li>
<li>用户下载sr.cer双击运行，添加到“本地计算机”，“就所有证书都放入下列存储”，选择“受信任的根证书颁发机构”，一路确定即可。</li>
</ul>
</li>
</ol>
</li>
<li><p>linux下配置方式与window下类似，只不过建议所有的keytool都使用绝对路径，因为locate keytool可以看到ubuntu有很多keytool。</p>
</li>
<li><p>错误问题</p>
<ul>
<li>访问https时提示“您的连接不是私密连接…此服务器无法证明其所在网域是…”，但是可以继续访问。</li>
<li>由于证书是自己给自己颁发的，所以浏览器不相信证书颁发机构。原因是浏览器没有 CA 证书，只有 CA 证书，服务器才能够确定这个用户就是真实的访问请求（比如不是代理过来的）。</li>
<li>如果我们的证书不是自己颁发，而是去靠谱的机构去申请的，就不会出现这样的问题，因为靠谱机构的证书会放到浏览器中，浏览器会各种安全检查。初次尝试的同学可以去 startssl.com 申请一个免费的证书，相关操作可以参考<a href="http://www.tuicool.com/articles/VbeEfyz" target="_blank" rel="external">startssl申请免费ssl证书的方法</a>，需要注册邮箱，域名验证，证书下载…</li>
</ul>
</li>
</ul>
<h2 id="问题与解决"><a href="#问题与解决" class="headerlink" title="问题与解决"></a>问题与解决</h2><hr>
<h3 id="tomcat提示Choose-unique-values-for-the-webAppRootKey"><a href="#tomcat提示Choose-unique-values-for-the-webAppRootKey" class="headerlink" title="tomcat提示Choose unique values for the webAppRootKey"></a>tomcat提示Choose unique values for the webAppRootKey</h3><ul>
<li>问题描述：一个tomcat发布多个web项目提示错误Choose unique values for the ‘webAppRootKey’</li>
<li>原因解析：Tomcat发布多个项目时抛的webAppRootKey错误,  原因是部署在同一容器中的Web项目，定义了相同的webAppRootKey或者都没有定义</li>
<li>解决方法：为后者指定或者为每个web都定义一个webAppRootKey</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">&lt;context-param&gt;</div><div class="line">    &lt;param-name&gt;webAppRootKey&lt;/param-name&gt;</div><div class="line">    &lt;param-value&gt;app1.root&lt;/param-value&gt;</div><div class="line">&lt;/context-param&gt;</div></pre></td></tr></table></figure>
<h3 id="ubuntu-tomcat提示isARPRequired-Z错误"><a href="#ubuntu-tomcat提示isARPRequired-Z错误" class="headerlink" title="ubuntu tomcat提示isARPRequired()Z错误"></a>ubuntu tomcat提示isARPRequired()Z错误</h3><ul>
<li>解决方法：重新下载官网的新版的tomcat。注意新版需要修改设置：端口修改、中文支持URLEncoding=utf-8、系统没有中文乱码。</li>
</ul>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Java-web/" rel="tag">#Java web</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/01/12/Software/Text editors 文本编辑/Vi and Vim/" rel="next" title="Vi and Vim">
                <i class="fa fa-chevron-left"></i> Vi and Vim
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/01/14/AIDeepLearning/DL Hardwares And Drivers/" rel="prev" title="Deep Learning Hardwares And Drivers">
                Deep Learning Hardwares And Drivers <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    


  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/statics/images/avatar.png"
               alt="gatewayzy" />
          <p class="site-author-name" itemprop="name">gatewayzy</p>
          <p class="site-description motion-element" itemprop="description">blog website with hexo and github pages</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">70</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">10</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              友情链接
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="https://github.com/gatewayzy" title="Github-gatewayzy" target="_blank">Github-gatewayzy</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://google.com/" title="Goolge" target="_blank">Goolge</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://wiki.jikexueyuan.com/" title="Wiki-jike" target="_blank">Wiki-jike</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Apache"><span class="nav-number">1.</span> <span class="nav-text">Apache</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Jetty"><span class="nav-number">2.</span> <span class="nav-text">Jetty</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Jetty介绍"><span class="nav-number">2.1.</span> <span class="nav-text">Jetty介绍</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#安装"><span class="nav-number">2.2.</span> <span class="nav-text">安装</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#主要端口号"><span class="nav-number">2.3.</span> <span class="nav-text">主要端口号</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Tomcat"><span class="nav-number">3.</span> <span class="nav-text">Tomcat</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Tomcat安装启动"><span class="nav-number">3.1.</span> <span class="nav-text">Tomcat安装启动</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#发布项目"><span class="nav-number">3.2.</span> <span class="nav-text">发布项目</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Tomcat-界面管理与设置"><span class="nav-number">3.3.</span> <span class="nav-text">Tomcat 界面管理与设置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Tomcat主要端口"><span class="nav-number">3.4.</span> <span class="nav-text">Tomcat主要端口</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#tomcat的体系结构"><span class="nav-number">3.5.</span> <span class="nav-text">tomcat的体系结构</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#catalina-bat"><span class="nav-number">3.6.</span> <span class="nav-text">catalina.bat</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Tomcat集群"><span class="nav-number">3.7.</span> <span class="nav-text">Tomcat集群</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#安装与配置"><span class="nav-number">3.7.1.</span> <span class="nav-text">安装与配置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#共享session"><span class="nav-number">3.7.2.</span> <span class="nav-text">共享session</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#脚本管理tomcat集群"><span class="nav-number">3.7.3.</span> <span class="nav-text">脚本管理tomcat集群</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#tomcat-启用-https"><span class="nav-number">3.8.</span> <span class="nav-text">tomcat 启用 https</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#问题与解决"><span class="nav-number">4.</span> <span class="nav-text">问题与解决</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#tomcat提示Choose-unique-values-for-the-webAppRootKey"><span class="nav-number">4.1.</span> <span class="nav-text">tomcat提示Choose unique values for the webAppRootKey</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ubuntu-tomcat提示isARPRequired-Z错误"><span class="nav-number">4.2.</span> <span class="nav-text">ubuntu tomcat提示isARPRequired()Z错误</span></a></li></ol></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">gatewayzy</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  



  




  
  

  
  <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
        processEscapes: true,
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
  </script>

  <script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for (i=0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';
      }
    });
  </script>
  <script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>



  

  
<script type="text/javascript" async src="//push.zhanzhang.baidu.com/push.js">
</script>


</body>
</html>
